home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / trans.com / KEYWORD.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-02-01  |  3.3 KB  |  105 lines

  1. { ********************************************************************* }
  2. { KEYWORD                                                               }
  3. {                                                                       }
  4. { Copyright 1989 by Gil Yoder                                           }
  5. { P.O. Box 307                                                          }
  6. { Coalgate, OK 74538                                                    }
  7. {                                                                       }
  8. { CIS#: 73237,3103                                                      }
  9. {                                                                       }
  10. { You may use, copy, distribute, and modify KEYWORD without restriction }
  11. { but you may not sell KEYWORD or programs derived herefrom.  If you do }
  12. { modify the program, the author of KEYWORD would appreciate notifica-  }
  13. { tion.                                                                 }
  14. { ********************************************************************* }
  15. { KEYWORD is a simple program that reports the word values of any key   }
  16. { you press.  Simple run the program from the command line and press    }
  17. { keys.  If the key is a printable character the key will be displayed. }
  18. { In any case the value of the key will be displayed in hexadecimal.    }
  19. { To exit from the program press the escape key.                        }
  20. { ********************************************************************* }
  21. { KEYWORD requires Turbo Professional Toolbox from Turbo Power in order }
  22. { for it to be recompiled.  Compile with TP 5.5.                        }
  23. { ********************************************************************* }
  24.  
  25.  
  26.  
  27. program keyword;
  28.  
  29.  
  30. (*************************************)
  31. (*                                   *)
  32. (*  Object Oriented Keyword Program  *)
  33. (*                                   *)
  34. (*************************************)
  35.  
  36. uses TpEnhKbd,        {Must Comment out TpEnhKbd before using ID}
  37.      TpCrt,Std_CVT,
  38.      TpMacro;
  39.  
  40. type
  41.  
  42.   keys = object                {My first simple object!}
  43.     keyw : word;               {Binary key representation}
  44.     keystr : String[4];        {String key representation}
  45.     procedure get;             {Method to get a key for the keyboard}
  46.     procedure out;             {Method to send KeyStr to Crt}
  47.     function isesc : boolean;  {Method to check for Escape key}
  48.   end;
  49.  
  50.  
  51. (*************************************)
  52. (*          Keys Methods             *)
  53. (*************************************)
  54.  
  55.  
  56. procedure keys.get;
  57. var
  58.   i : byte;
  59.   h : word;
  60. begin
  61.   keyw := readkeyword;
  62.   h := keyw;
  63.   keystr := '';
  64.   repeat
  65.     i := h mod 16;
  66.     if i < 10 then
  67.       keystr := char(i+$30) + keystr
  68.     else
  69.       keystr := char(i+$37) + keystr;
  70.     h := h div 16;
  71.   until h = 0;
  72.   while length(keystr) < 4 do
  73.     keystr := '0'+keystr;
  74. end;
  75.  
  76. procedure keys.out;
  77. var
  78.   ch : char absolute keyw;
  79.   special : boolean;
  80.   s : string;
  81.  
  82. begin
  83.   write(keystr,' = ');
  84.   keytostring(keyw,s,special);
  85.   writeln(s)
  86. end;
  87.  
  88. function keys.isesc : boolean;
  89. begin
  90.   isesc := keyw = esc_key;
  91. end;
  92.  
  93. (******* End of Keys Methods *********)
  94.  
  95. var
  96.   key : keys;   {Instantiate "key" as an object of type "keys"}
  97.  
  98.  
  99. begin
  100.   repeat
  101.     key.get;
  102.     key.out;
  103.   until key.isesc;
  104. end.
  105.